package cn.zwx.member.svc.config;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zhangwenxue
 */
@Data
@Component
@ConfigurationProperties(prefix = "sms")
public class SmsConfig {

    /**
     * accessKey
     */
    private String accessKey;
    /**
     * secret
     */
    private String secret;
    /**
     * endpoint
     */
    private String endpoint;
    /**
     * 签名
     */
    private String signName;
    /**
     * 模板配置
     */
    private List<TemplateInfo> templates;


    @Data
    public static class TemplateInfo{
      /**
       * 模板code
       */
      private String id;
      /**
       * 模板参数
       */
      private String temp;
    }


    @Bean
    public Client createClient() throws Exception {
        final Config config = new Config()
                .setAccessKeyId(accessKey)
                .setAccessKeySecret(secret)
                .setEndpoint(endpoint);
        return new Client(config);
    }
}
